#include <iostream>
#include <cstring>

using namespace std;

int main(void)
{
	char str[100];
	cout << "string: ";
	int z = 0;
	do
	{
		scanf("%c", &str[z]);
		str[z + 1] = '\0';
		z ++;
	}
	while(str[z - 1] != '#');

	int l = strlen(str);

	char mo[100];
	int lm;
	int a = 0;
	int j;

	int m, n;
	int t;
	for(int i = l - 1; i >= 0; i --)
	{
//		cout << str[i];
//		cout << a;
		if((str[i] != ' ') && ((str[i + 1] == ' ') || (str[i + 1] == '\0')))
		{
//			cout << "###" << endl;
			a = 1;
			j = 0;
		}
		if((a == 1) && (str[i] != ' '))
		{
//			cout << "###" << endl;
			mo[j] = str[i];
			mo[j + 1] = '\0';
			j ++;
		}
		if(((a == 1) && (str[i] == ' ')) || (i == 0))
		{
//			cout << "###" << endl;
			a = 0;
			j = 0;
			lm = strlen(mo);
			for(m = 0, n = lm - 1; n > m; m ++, n --)
			{
				t = mo[m];
				mo[m] = mo[n];
				mo[n] = t;		
			}
			cout << mo;
		}
		if(str[i] == ' ')
			cout << " ";

	}

	cout << endl;

	return 0;
}
